package com.xiaoyu.commonlib.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.xiaoyu.commonlib.R;


/**
 * @Author: JX
 * @Date: 2018/5/14 14:12
 */
public abstract class BaseDialog extends Dialog implements View.OnClickListener {

    private Context mContext;
    private View mContentView;
    private TextView mTitleTextView, mLeftTextView, mRightTextView, base_dialog_details;

    public BaseDialog(Context context) {
        super(context, R.style.BaseDialogStyle);
        mContext = context;
    }

    public Context getmContext() {
        return mContext;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }


    protected abstract String getTitleText();

    protected abstract String getDetailsText();

    protected abstract String getLeftText();

    protected abstract String getRightText();

    protected abstract void leftClick();

    protected abstract void rightClick();

    private void init() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.base_dialog, null);
        mTitleTextView = mContentView.findViewById(R.id.base_dialog_title);
        mLeftTextView = mContentView.findViewById(R.id.base_dialog_cancel);
        mRightTextView = mContentView.findViewById(R.id.base_dialog_confirm);
        base_dialog_details = mContentView.findViewById(R.id.base_dialog_details);
        if (!TextUtils.isEmpty(getDetailsText())) {
            base_dialog_details.setVisibility(View.VISIBLE);
            base_dialog_details.setText(getDetailsText());
        }
        mTitleTextView.setText(getTitleText());
        mLeftTextView.setText(getLeftText());
        mRightTextView.setText(getRightText());
        mLeftTextView.setOnClickListener(this);
        mRightTextView.setOnClickListener(this);
        setContentView(mContentView);
    }

    @Override
    public void onClick(View v) {
        if (v == mLeftTextView) {
            leftClick();
        } else if (v == mRightTextView) {
            rightClick();
        }
    }

    @Override
    public void show() {
        super.show();
    }

    public TextView getmTitleTextView() {
        return mTitleTextView;
    }

    public TextView getmRightTextView() {
        return mRightTextView;
    }

    public TextView getmLeftTextView() {
        return mLeftTextView;
    }

}
